Skip to content

fix(http_spec): make LLMSpec.model_name always return a string - #404

Merged
msoedov merged 1 commit into
msoedov:mainfrom
fouadbehtaher:fix/model-name-non-object-body
Nov 27, 2026
Merged

msoedov merged 1 commit into
msoedov:mainfrom
fouadbehtaher:fix/model-name-non-object-body

Conversation

@fouadbehtaher

Copy link
Copy Markdown
Contributor

What

LLMSpec.model_name is documented to return the model field of the request body, or "unknown". It did not hold up in two cases:

  1. A body that is valid JSON but not an object ([1, 2], "text", null) raised AttributeError on .get. fuzzer.py only survived because getattr(..., "unknown") swallows AttributeError.
  2. A non-string model (null, a number, a list, an object) was returned as is. A list or dict then reaches calculate_cost, where model not in PRICING raises TypeError: unhashable type.

Change

model_name returns "unknown" unless the body is a JSON object whose model is a non-empty string.

How I tested

  • Added tests/unit/test_model_name.py: 13 parametrized cases (valid, missing, empty, not JSON, non-object JSON, non-string model) plus a check that the result is safe to pass to calculate_cost.
  • The new tests fail on main (10 failed) and pass with the change.
  • pytest tests/unit tests/integration: 538 passed, 2 skipped. black and flake8 clean.

Checklist

  • One change only
  • Tests added
  • No real secrets in code, tests or description
  • No docs change needed (behaviour matches the existing docstring)

Fouad Taher

@msoedov msoedov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thx for the patch

@msoedov
msoedov merged commit 2baacb8 into msoedov:main Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants